﻿// -------------------------------------------------------------------------
//    @FileName         :    NFBaseDefine.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-16
//    @Email            :    445267987@qq.com
//    @Module           :    NFBaseDefine
//
// -------------------------------------------------------------------------

#include "NFBaseDefine.h"

#include <NFComm/NFCore/NFCommon.h>

#include "NFComm/NFCore/NFStringUtility.h"

TClientVersion ParseClientVersion(const std::string& strClientVerion)
{
    TClientVersion stVersion;
    memset(&stVersion, 0, sizeof(stVersion));

    std::vector<int> versionVec;
    NFStringUtility::SplitStringToVector(strClientVerion, ".", versionVec);

    if (versionVec.size() > 0)
    {
        stVersion.m_iBigVer = versionVec[0];
    }

    if (versionVec.size() > 1)
    {
        stVersion.m_iMidVer = versionVec[1];
    }

    if (versionVec.size() > 2)
    {
        stVersion.m_iMinVer = versionVec[2];
    }

    if (versionVec.size() > 3)
    {
        stVersion.m_iBuildCnt = versionVec[3];
    }

    return stVersion;
}

int CompareClientVersion(TClientVersion &stLeftVer, TClientVersion &stRightVer)
{
    //big ver
    if (stRightVer.m_iBigVer > stLeftVer.m_iBigVer)
    {
        return 1;
    }
    else if (stRightVer.m_iBigVer < stLeftVer.m_iBigVer)
    {
        return -1;
    }

    //mid ver
    if (stRightVer.m_iMidVer > stLeftVer.m_iMidVer)
    {
        return 1;
    }
    else if (stRightVer.m_iMidVer < stLeftVer.m_iMidVer)
    {
        return -1;
    }

    //min ver
    if (stRightVer.m_iMinVer > stLeftVer.m_iMinVer)
    {
        return 1;
    }
    else if (stRightVer.m_iMinVer < stLeftVer.m_iMinVer)
    {
        return -1;
    }

    if (stRightVer.m_iBuildCnt > stLeftVer.m_iBuildCnt)
    {
        return 1;
    }
    else if (stRightVer.m_iBuildCnt < stLeftVer.m_iBuildCnt)
    {
        return -1;
    }

    return 0;
}
